<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Java静态变量与成员变量深度解析</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .card-hover {
            transition: all 0.3s ease;
            border: 1px solid transparent;
        }
        
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
            border: 1px solid rgba(102, 126, 234, 0.3);
        }
        
        .text-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
        
        .code-block {
            background: #2d3748;
            color: #e2e8f0;
            border-radius: 8px;
            padding: 1rem;
            font-family: 'Consolas', 'Monaco', monospace;
            position: relative;
            overflow-x: auto;
        }
        
        .code-block::before {
            content: 'Java';
            position: absolute;
            top: 0;
            right: 0;
            background: rgba(102, 126, 234, 0.8);
            color: white;
            padding: 0.25rem 0.75rem;
            border-radius: 0 8px 0 8px;
            font-size: 0.75rem;
            font-weight: 600;
        }
        
        .feature-icon {
            width: 60px;
            height: 60px;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 12px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            font-size: 24px;
            margin-bottom: 1rem;
        }
        
        .section-divider {
            height: 2px;
            background: linear-gradient(to right, transparent, #667eea, transparent);
            margin: 3rem 0;
        }
        
        .highlight-box {
            background: linear-gradient(135deg, rgba(102, 126, 234, 0.1) 0%, rgba(118, 75, 162, 0.1) 100%);
            border-left: 4px solid #667eea;
            padding: 1.5rem;
            border-radius: 8px;
            margin: 1.5rem 0;
        }
        
        .comparison-table {
            background: white;
            border-radius: 12px;
            overflow: hidden;
            box-shadow: 0 10px 30px rgba(0,0,0,0.1);
        }
        
        .comparison-table th {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 1rem;
            text-align: left;
            font-weight: 600;
        }
        
        .comparison-table td {
            padding: 1rem;
            border-bottom: 1px solid #e2e8f0;
        }
        
        .comparison-table tr:hover {
            background: rgba(102, 126, 234, 0.05);
        }
        
        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        
        .animate-fadeInUp {
            animation: fadeInUp 0.8s ease-out;
        }
        
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <div class="hero-gradient text-white py-20">
        <div class="container mx-auto px-6">
            <div class="max-w-4xl mx-auto text-center animate-fadeInUp">
                <h1 class="text-5xl md:text-6xl font-bold mb-6">
                    Java静态变量与成员变量
                </h1>
                <p class="text-xl md:text-2xl opacity-90 mb-8">
                    深入理解Java中两种核心变量类型的本质区别
                </p>
                <div class="flex justify-center space-x-4">
                    <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full text-sm">
                        <i class="fas fa-book-open mr-2"></i>深度解析
                    </span>
                    <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full text-sm">
                        <i class="fas fa-code mr-2"></i>实例对比
                    </span>
                    <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full text-sm">
                        <i class="fas fa-chart-line mr-2"></i>最佳实践
                    </span>
                </div>
            </div>
        </div>
    </div>

    <!-- Main Content -->
    <div class="container mx-auto px-6 py-12">
        <div class="max-w-6xl mx-auto">
            
            <!-- Introduction -->
            <div class="bg-white rounded-2xl shadow-xl p-8 mb-8 card-hover">
                <p class="text-lg leading-relaxed text-gray-700">
                    在Java编程语言中，静态变量（Static Variable）和成员变量（Instance Variable）是两种不同类型的变量，它们在类的定义和使用上有着显著的区别。理解这两种变量的特性对于编写高效、可维护的Java代码至关重要。
                </p>
            </div>

            <!-- Visual Comparison Diagram -->
            <div class="bg-white rounded-2xl shadow-xl p-8 mb-8">
                <h2 class="text-3xl font-bold mb-6 text-center text-gradient">变量类型关系图</h2>
                <div class="mermaid">
                    graph TD
                        A[Java变量类型] --> B[静态变量]
                        A --> C[成员变量]
                        B --> D[类级别]
                        B --> E[所有对象共享]
                        B --> F[static关键字]
                        C --> G[对象级别]
                        C --> H[每个对象独立]
                        C --> I[无static关键字]
                        
                        style A fill:#667eea,stroke:#fff,stroke-width:2px,color:#fff
                        style B fill:#764ba2,stroke:#fff,stroke-width:2px,color:#fff
                        style C fill:#764ba2,stroke:#fff,stroke-width:2px,color:#fff
                </div>
            </div>

            <!-- Key Differences Grid -->
            <div class="grid md:grid-cols-2 gap-8 mb-12">
                <!-- Static Variable Card -->
                <div class="bg-white rounded-2xl shadow-xl p-8 card-hover">
                    <div class="feature-icon">
                        <i class="fas fa-layer-group"></i>
                    </div>
                    <h3 class="text-2xl font-bold mb-4 text-gradient">静态变量</h3>
                    <ul class="space-y-3 text-gray-700">
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-purple-600 mt-1 mr-3"></i>
                            <span>使用 <code class="bg-gray-100 px-2 py-1 rounded">static</code> 关键字修饰</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-purple-600 mt-1 mr-3"></i>
                            <span>属于类本身，所有对象共享</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-purple-600 mt-1 mr-3"></i>
                            <span>类加载时分配内存</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-purple-600 mt-1 mr-3"></i>
                            <span>存储在方法区的静态存储区</span>
                        </li>
                    </ul>
                </div>

                <!-- Instance Variable Card -->
                <div class="bg-white rounded-2xl shadow-xl p-8 card-hover">
                    <div class="feature-icon">
                        <i class="fas fa-cube"></i>
                    </div>
                    <h3 class="text-2xl font-bold mb-4 text-gradient">成员变量</h3>
                    <ul class="space-y-3 text-gray-700">
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-purple-600 mt-1 mr-3"></i>
                            <span>不使用 <code class="bg-gray-100 px-2 py-1 rounded">static</code> 关键字</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-purple-600 mt-1 mr-3"></i>
                            <span>属于对象实例，每个对象独立</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-purple-600 mt-1 mr-3"></i>
                            <span>对象创建时分配内存</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-purple-600 mt-1 mr-3"></i>
                            <span>存储在堆内存中</span>
                        </li>
                    </ul>
                </div>
            </div>

            <!-- Detailed Comparison Table -->
            <div class="mb-12">
                <h2 class="text-3xl font-bold mb-6 text-center">详细对比分析</h2>
                <div class="comparison-table">
                    <table class="w-full">
                        <thead>
                            <tr>
                                <th class="w-1/3">特性</th>
                                <th class="w-1/3">静态变量</th>
                                <th class="w-1/3">成员变量</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td class="font-semibold">内存分配时机</td>
                                <td>类加载时</td>
                                <td>对象创建时</td>
                            </tr>
                            <tr>
                                <td class="font-semibold">存储位置</td>
                                <td>方法区（静态存储区）</td>
                                <td>堆内存</td>
                            </tr>
                            <tr>
                                <td class="font-semibold">生命周期</td>
                                <td>与类相同（类加载到卸载）</td>
                                <td>与对象相同（创建到垃圾回收）</td>
                            </tr>
                            <tr>
                                <td class="font-semibold">访问方式</td>
                                <td>类名.变量名 或 对象.变量名</td>
                                <td>仅通过对象.变量名</td>
                            </tr>
                            <tr>
                                <td class="font-semibold">内存占用</td>
                                <td>全局唯一，节省内存</td>
                                <td>每个对象一份，占用较多</td>
                            </tr>
                            <tr>
                                <td class="font-semibold">线程安全</td>
                                <td>需要同步控制</td>
                                <td>相对安全（对象独立）</td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>

            <!-- Code Examples -->
            <div class="bg-white rounded-2xl shadow-xl p-8 mb-8">
                <h2 class="text-3xl font-bold mb-6">代码示例</h2>
                
                <div class="mb-8">
                    <h3 class="text-xl font-semibold mb-4 flex items-center">
                        <i class="fas fa-code text-purple-600 mr-3"></i>
                        类定义示例
                    </h3>
                    <div class="code-block">
                        <pre>public class Student {
    // 静态变量 - 记录学生总数
    private static int totalStudents = 0;
    
    // 成员变量 - 每个学生的独立属性
    private String name;
    private int age;
    private String studentId;
    
    // 构造方法
    public Student(String name, int age) {
        this.name = name;
        this.age = age;
        this.studentId = generateId();
        totalStudents++; // 每创建一个对象，总数加1
    }
    
    // 静态方法访问静态变量
    public static int getTotalStudents() {
        return totalStudents;
    }
    
    // 实例方法访问成员变量
    public String getInfo() {
        return "姓名: " + name + ", 年龄: " + age;
    }
}</pre>
                    </div